package com.rng.dateless;

import android.app.DialogFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.NumberPicker;
import android.widget.RadioButton;

/**
 * Created by tkoh on 04.11.2014.
 */
public class NumberPickerDialog extends DialogFragment implements View.OnClickListener {
    RadioButton days;
    RadioButton months;
    RadioButton years;
    NumberPicker picker;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        getDialog().setTitle("Title!");
        View v = inflater.inflate(R.layout.add_recurrence_dialog, null);
        v.findViewById(R.id.number_picker_button_ok).setOnClickListener(this);
        v.findViewById(R.id.number_picker_button_cancel).setOnClickListener(this);
        picker = (NumberPicker)v.findViewById(R.id.numberPicker1);
        days = (RadioButton)v.findViewById(R.id.radioButtonDays);
        months = (RadioButton)v.findViewById(R.id.radioButtonMonths);
        years = (RadioButton)v.findViewById(R.id.radioButtonYears);
        return v;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.number_picker_button_ok:
                int type;
                NewEvent activity = (NewEvent) getActivity();
                if (days.isEnabled()) {
                    type = RecurrencyItem.DAYS;
                }
                else if (months.isEnabled()) {
                    type = RecurrencyItem.MONTHS;
                }
                else {
                    type = RecurrencyItem.YEARS;
                }
                activity.onUserAddRecurrence(type,picker.getValue());
                break;
            case R.id.number_picker_button_cancel:
            default:

        }
    }
}
